<script setup>
import { reactive } from 'vue'

//定义时间传递对象
const $emits = defineEmits(['searchParamsBtnEmits', 'resetParamsBtnEmits'])

const searchForm = reactive({
  title: '',
  name: '',
  searchTime: ''
})

//搜索用户信息参数传递
const searchBtn = () => {
  $emits('searchParamsBtnEmits', searchForm)
}

const resetBtn = () => {
  Object.assign(searchForm, {
    title: '',
    name: '',
    searchTime: ''
  })
  $emits('resetParamsBtnEmits')
}
</script>

<template>
  <div class="search">
    <el-form :model="searchForm">
      <el-row>
        <el-col :span="8">
          <el-form-item label="文章名称" label-width="100px">
            <el-input v-model="searchForm.title" placeholder="请输入文章名称" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="作者" label-width="80px">
            <el-input v-model="searchForm.name" placeholder="请输入作者" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="发布时间" label-width="100px">
            <el-date-picker
              v-model="searchForm.searchTime"
              type="daterange"
              format="YYYY-MM-DD"
              range-separator="到"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            />
          </el-form-item>
        </el-col>

        <el-col style="text-align: center" :span="8">
          <el-button type="primary" @click="searchBtn">
            <el-icon>
              <Search />
            </el-icon>
            <span>搜索</span>
          </el-button>
          <el-button @click="resetBtn">
            <el-icon>
              <RefreshRight />
            </el-icon>
            <span>重置</span>
          </el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<style scoped lang="less">
.search {
  .el-form-item {
    font-weight: 700;
    padding: 0 30px 0 30px;
  }

  margin-top: 20px;

  .el-col {
    margin-bottom: 20px;
  }

  .el-button {
    width: 80px;
  }
}
</style>
